﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Programonica.Deadhand.Scene;
using Programonica.Igramonica.Graphics;
using Programonica.Igramonica.Scene;
using Programonica.Igramonica.UserInterface;

namespace Programonica.Deadhand.UserInterface
{
    public class LoadDockScreen : LoadLevelScreen
    {
        #region Поля

        private SliderControl progressSlider;

        private DockScene dockScene;

        #endregion

        //---------------------------------------------------------------------------

        #region Свойства

        #endregion

        //---------------------------------------------------------------------------

        #region Инициализация

        public LoadDockScreen()
        {

        }
        
        public override void LoadContent()
        {
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            
            this.progressSlider = new SliderControl();

            this.progressSlider.Left = viewport.Width / 2 - 100.0f;
            this.progressSlider.Top = viewport.Height / 1.5f;

            this.progressSlider.AddValue("0%");
            this.progressSlider.AddValue("10%");
            this.progressSlider.AddValue("20%");
            this.progressSlider.AddValue("30%");
            this.progressSlider.AddValue("40%");
            this.progressSlider.AddValue("50%");
            this.progressSlider.AddValue("60%");
            this.progressSlider.AddValue("70%");
            this.progressSlider.AddValue("80%");
            this.progressSlider.AddValue("90%");
            this.progressSlider.AddValue("100%");

            this.progressSlider.Value = 0;

            this.progressSlider.Text = " Загрузка";

            AddControl(progressSlider);

            base.LoadContent();
        }

        #endregion

        //---------------------------------------------------------------------------

        #region Обновление и отображение

        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void HandleInput()
        {
            base.HandleInput();
        }

        public override void Draw(GameTime gameTime)
        {
            ScreenManager.GraphicsDevice.Clear(new Color(255, 255, 255));
            
            base.Draw(gameTime);
        }

        #endregion

        //---------------------------------------------------------------------------

        #region Многозадачность

        public override void StartLoading()
        {
            this.dockScene = new DockScene(ScreenManager.Game);

            dockScene.LoadContent(levelLoader_IncProgress);

            base.StartLoading();
        }

        public override void EndLoading()
        {
            foreach (GameScreen screen in ScreenManager.GetScreens())
            {
                screen.ExitScreen();
            }

            ScreenManager.AddScreen(new GameplayScreen(this.dockScene));
            
            base.EndLoading();
        }

        private void levelLoader_IncProgress()
        {
            this.progressSlider.Value++;
        }

        #endregion
    }
}